//
//  ChangePendingOrderViewController.m
//  DaiShengInvest
//
//  Created by 张睿 on 2017/7/6.
//  Copyright © 2017年 davinci. All rights reserved.
//

#import "ChangePendingOrderViewController.h"
#import "ChangePendingOrderView.h"


@interface ChangePendingOrderViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong)ChangePendingOrderView * changView;

@property (nonatomic, weak)UIImageView * backImageView;

@property (nonatomic, strong)UIButton * sureButton;

@property (nonatomic, strong)UILabel * priceLabel;
@property (nonatomic, strong)UITextField * priceTextField;
@property (nonatomic, strong)UILabel * stopLoseLabel;
@property (nonatomic, strong)UITextField * stopLoseTextField;
@property (nonatomic, strong)UILabel * stopWinLabel;
@property (nonatomic, strong)UITextField * stopWinTextField;

@end

@implementation ChangePendingOrderViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setupNavBar];
    [self setupUI];
}

- (void)setupNavBar{
    
    self.title = @"修改订单";
    
    UIButton * backButton = [[UIButton alloc] init];
    
    backButton.frame = CGRectMake(15 * SCREENH6, 5 * SCREENH6, 12 * SCREENH6, 20 * SCREENH6);
    [backButton setImage:[UIImage imageNamed:@"1返回"] forState:UIControlStateNormal];
    [backButton addTarget:self action:@selector(backToAccountView) forControlEvents:UIControlEventTouchUpInside];
    
    UIBarButtonItem * leftButton = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    
    self.navigationItem.leftBarButtonItem = leftButton;
}



- (void)setupUI{
    
    //    self.edgesForExtendedLayout = UIRectEdgeNone;
    
    UIImageView * backImage = [[UIImageView alloc] init];
    
    backImage.image = [UIImage imageNamed:@"背景"];
    
    self.backImageView = backImage;
    
    [self.view addSubview:self.backImageView];
    
    //215
    
    self.changView = [[ChangePendingOrderView alloc] initWithFrame:CGRectMake(0, 64 * SCREENH6, SCREEN_WIDTH, 215 * SCREEN_WIDTH)];
    
    [self.view addSubview:self.changView];

    
    self.priceLabel = [self setupLabel:@"价格"];
    
    [self.view addSubview:self.priceLabel];
    
    self.priceTextField = [self setupTextField:@"价格"];
    
    [self.view addSubview:self.priceTextField];
    
    self.stopLoseLabel = [self setupLabel:@"止损点数"];
    
    [self.view addSubview:self.stopLoseLabel];
    
    self.stopLoseTextField = [self setupTextField:@"价格"];
    
    [self.view addSubview:self.stopLoseTextField];
    
    self.stopWinLabel = [self setupLabel:@"止盈点数"];
    
    [self.view addSubview:self.stopWinLabel];
    
    self.stopWinTextField = [self setupTextField:@"价格"];
    
    [self.view addSubview:self.stopWinTextField];
    
    
    
    self.sureButton = [[UIButton alloc] initWithFrame:CGRectMake(15 * SCREENH6, 580 * SCREENH6, 345 * SCREENH6, 50 * SCREENH6)];
    
    [self.sureButton setTitle:@"确认修改" forState:UIControlStateNormal];
    self.sureButton.titleLabel.font = [UIFont fontWithName:@"PingFangSC-Medium" size:15 * SCREENH6];//
    [self.sureButton setBackgroundImage:[UIImage imageNamed:@"注册"] forState:UIControlStateNormal];
    self.sureButton.layer.borderColor = [[UIColor blackColor] CGColor];
    //边框宽度
    //    saveButton.layer.borderWidth =1.0f;
    //处理圆角
    self.sureButton.layer.cornerRadius =5.0f;
    [self.sureButton setTitleColor:ColorWithRGB(0xffffff) forState:UIControlStateNormal];
    [self.sureButton addTarget:self action:@selector(didChangeButton) forControlEvents:UIControlEventTouchUpInside];
    
    [self.view addSubview:self.sureButton];
}



- (void)viewDidLayoutSubviews{
    
    [self.backImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.trailing.top.bottom.mas_equalTo(self.view);
    }];
    
    
    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.view).offset(15 * SCREENH6);
        make.top.mas_equalTo(self.view).offset(305 * SCREENH6);
    }];
    
    
    [self.priceTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.view).offset(90 * SCREENH6);
        make.centerY.mas_equalTo(self.priceLabel);
        make.trailing.mas_equalTo(self.view).offset(-15 * SCREENH6);
        make.height.mas_equalTo(40 * SCREENH6);
    }];

    [self.stopLoseTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.priceTextField.mas_bottom).offset(50 * SCREENH6);
        make.leading.trailing.height.mas_equalTo(self.priceTextField);
    }];
    
    [self.stopLoseLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.priceLabel);
        make.centerY.mas_equalTo(self.stopLoseTextField);
    }];

    [self.stopWinTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.stopLoseTextField.mas_bottom).offset(50 * SCREENH6);
        make.leading.trailing.height.mas_equalTo(self.stopLoseTextField);
    }];
    
    [self.stopWinLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.stopLoseLabel);
        make.centerY.mas_equalTo(self.stopWinTextField);
    }];
}




- (UILabel *)setupLabel:(NSString *)string{
    
    UILabel * label = [UILabel new];
    
    label.font = [UIFont fontWithName:@"PingFangSC-Medium" size:15 * SCREENH6];
    label.textColor = ColorWithRGB(0xffffff);
    label.text = string;
    
    return label;
}


- (UITextField *)setupTextField:(NSString *)name{
    
    
    UITextField * textFiled = [[UITextField alloc] init];
    
    textFiled.borderStyle = UITextBorderStyleNone;
    textFiled.backgroundColor = [UIColor clearColor];
    
    textFiled.background = [UIImage imageNamed:name];
    textFiled.textAlignment = UITextAlignmentCenter;
    
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSForegroundColorAttributeName] = ColorWithRGB(0xeeeeee);
    attrs[NSFontAttributeName] = [UIFont fontWithName:@"PingFangSC-Regular" size:15 * SCREENH6];
    textFiled.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"未设置" attributes:attrs];
    textFiled.font = [UIFont fontWithName:@"PingFangSC-Regular" size:15 * SCREENH6];
    textFiled.textColor = ColorWithRGB(0xeeeeee);
    
    
    UIButton * reduceButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40 * SCREENH6, 40 * SCREENH6)];
    
    reduceButton.backgroundColor = [UIColor clearColor];
    [reduceButton addTarget:self action:@selector(didReduceButton:) forControlEvents:UIControlEventTouchUpInside];
    
    
    [textFiled addSubview:reduceButton];
    
    textFiled.leftView = reduceButton;
    textFiled.leftViewMode = UITextFieldViewModeAlways;
    
    
    UIButton * addButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40 * SCREENH6, 40 * SCREENH6)];
    
    addButton.backgroundColor = [UIColor clearColor];
    [addButton addTarget:self action:@selector(didAddButton:) forControlEvents:UIControlEventTouchUpInside];
    
    [textFiled addSubview:addButton];
    
    textFiled.rightView = addButton;
    textFiled.rightViewMode = UITextFieldViewModeAlways;
    
    textFiled.keyboardType = UIKeyboardTypeNumberPad;
    textFiled.keyboardAppearance = UIKeyboardAppearanceDark;
    
    
    return textFiled;
}


//点击确认修改按钮
- (void)didChangeButton{
    
    
    
    
}


//点击减少按钮
- (void)didReduceButton:(UIButton *)button{
    
    
}



//点击添加按钮
- (void)didAddButton:(UIButton *)button{
    
    
    
    
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
    [self.priceTextField resignFirstResponder];
    [self.stopLoseTextField resignFirstResponder];
    [self.stopWinTextField resignFirstResponder];
}


- (void)backToAccountView{
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
